import { defineStore } from 'pinia'

export const useUserStore = defineStore({
	id: 'USER',
	state: () => ({
		token: '',
	}),

	actions: {
		SET_TOKEN(token: string) {
			// 缓存在本地
			localStorage.setItem('token', token)
			// 存储在内存
			this.token = token
		},

		GET_TOKEN(): string | null {
			return localStorage.getItem('token') || this.token
		},

		REMOVE_TOKEN(): void {
			this.token = ''
			localStorage.removeItem('token')
			return void 0
		},
	},
})
